#include <bits/stdc++.h>
using namespace std;
int n;
long long a[1010],cnt,b[1010];
long long gethyt(){
	string st;
	long long ans=0,c=0,tot=0;
	cin>>st;
	for(int i=0;i<st.size();i++){
		if(st[i]>='0'&&'9'>=st[i]){
			ans=ans*10+st[i]-'0';
		}else if(st[i]=='.'){
			if(ans>255||c>3) return -1;
			tot=tot*256+ans;
			c++;
			ans=0;
		}else if(st[i]==':'){
			if(c!=3||ans>255) return -1;
			tot=tot*256+ans;
			ans=0;
		}else return -1;
	}
	if(c!=3||ans>65535) return -1;
	else return tot*65536+ans;
}
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		string st;
		int o=0;
		cin>>st;
		long long t=gethyt();
		if(t==-1){
			cout<<"ERR"<<endl;
			continue ;
		}
		if(st[0]=='S'){
			for(int j=1;j<=cnt;j++){
				if(t==a[j]){
					cout<<"FAIL"<<endl;
					o=1;
					break;
				}
			}
			if(o==0){
				cout<<"OK"<<endl;
				a[++cnt]=t;
				b[cnt]=i;
			}
		}
		if(st[0]=='C'){
			for(int j=1;j<=cnt;j++){
				if(t==a[j]){
					cout<<b[j]<<endl;
					o=1;
					break;
				}
			}
			if(o==0) cout<<"FAIL"<<endl;
		}
	}
return 0;
}
